package com.xiaotao.config;

import com.xiaotao.task.PostTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

@Configuration
@EnableScheduling
public class ScheduleConfig {

    @Resource
    private PostTask postTask;

    // 每30分钟更新一次推荐分数
    @Scheduled(fixedRate = 30 * 60 * 1000)
    public void updateRecommendations() {
        postTask.updatePostRecommendations();
    }

    // 每天凌晨2点清理过期帖子
    @Scheduled(cron = "0 0 2 * * ?")
    public void closeExpiredPosts() {
        postTask.closeExpiredPosts();
    }
}